﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace PTP.Mock
{
  public class MockStream : MemoryStream
  {
    protected MemoryStream sentData = new MemoryStream();

    public MockStream(byte[] buffer) : base(buffer) { }

    public override void Write(byte[] buffer, int offset, int count)
    {
      // store data to memory
      sentData.Write(buffer, offset, count);
    }

    public override void WriteByte(byte value)
    {
      // store data to memory
      sentData.WriteByte(value);
    }

    public byte[] GetSentData(bool clear)
    {
      byte[] result = sentData.ToArray();
      if (clear)
      {
        sentData.Dispose();
        sentData = new MemoryStream();
      }
      return result;
    }
  }
}
